package com.exam.online.system.service.impl;

import com.exam.online.system.dao.CourseDAO;
import com.exam.online.system.dao.CoursePaperDAO;
import com.exam.online.system.entity.Course;
import com.exam.online.system.entity.CoursePaper;
import com.exam.online.system.service.CoursePaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author yuzhen
 * @date 2019/5/6
 */
@Service
public class CoursePaperServiceImpl implements CoursePaperService {

    @Autowired
    private CoursePaperDAO coursePaperDAO;
    @Autowired
    private CourseDAO courseDAO;

    @Override
    public CoursePaper saveCoursePaper(String courseName, Integer paperId) {
        Course course = courseDAO.selectByCourseName(courseName);
        CoursePaper coursePaper = new CoursePaper();
        coursePaper.setCourseId(course.getId());
        coursePaper.setPaperId(paperId);
        int insert = coursePaperDAO.insert(coursePaper);
        if (insert > 0) {
            return coursePaper;
        } else {
            return null;
        }
    }
}
